{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f8f1e344",
   "metadata": {},
   "source": [
    "* 时间：2023-03-16\n",
    "* 课程：API、人工智能与机器学习\n",
    "* 本周主要内容：图像识别（人脸识别）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "3ee676fb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "401\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'error_message': 'AUTHENTICATION_ERROR'}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('C:/Users/15347635376/Pictures/liuyifei.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image_base64\":img,\n",
    "          \"api_key\":\"OSSnrEZ2GVU5Y78Of7qWn5AR\",\n",
    "          \"api_secret\":\"AdcOvRUAjV1ZEZyOH4INmQbf7W0gSaEc\"\n",
    "         }\n",
    "\n",
    "request_url = request_url\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "\n",
    "print (response.status_code)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f5f1c78f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
